package com.cherrish.demo.reflect;

import java.lang.reflect.InvocationHandler;
import java.lang.reflect.Method;

/**
 * @author cherrish
 * @time 2019-03-19 16:10
 * @name DynamicProxy
 * @desc:
 */
public class DynamicProxy implements InvocationHandler {

    private Object object;

    public DynamicProxy(Object object) {
        this.object = object;
    }

    @Override
    public Object invoke(Object proxy, Method method, Object[] args) throws Throwable {
        System.out.println("before method: ");
        System.out.println("The method: " + method);

        try{
            method.invoke(object, args);
        }catch (Exception e){
            System.out.println("exception: ");
            e.printStackTrace();
        }

        System.out.println("after method: ");
        return 1;
    }
}
